package com.wxb.hello.activemq.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * describe:
 *
 * @author : 王校兵
 * @version : v1.0
 * @time : 2017/7/29  21:39
 */
@RestController
public class Controller {

    @Autowired
    private JmsMessagingTemplate template;

    @Autowired
    private javax.jms.Queue queue;

    @RequestMapping("/email")
    public String sendTextEmail(@RequestBody JSONObject param) {
        String to = param.getString("to");
        String subject = param.getString("subject");
        String content = param.getString("content");

        HashMap<String, String> map = new HashMap<>();
        map.put("to", to);
        map.put("subject", subject);
        map.put("content", content);

        template.convertAndSend(queue, map);


        return "success";
    }

}
